package com.examiner.dao;

import com.examiner.bean.Examiner;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 考评员  dao层
 */
public interface ExaminerDao extends JpaRepository<Examiner,Integer>, JpaSpecificationExecutor<Examiner> {
    Examiner findExaminerByUserName(String userName);

    /**
     * 修改密码
     * @param id
     * @param newPassword
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update Examiner set password=:newPassword where id=:id",nativeQuery = true)
    int updatePassword(@Param("id")Integer id,
                       @Param("newPassword") String newPassword);

    /**
     * 查询分页总条数
     * @param query
     * @return
     */
    @Query(value = "select count(id) from examiner where user_name like %?1%",nativeQuery = true)
    int getTotal(String query);

    @Query(value = "select * from examiner where user_name like %?1%",nativeQuery = true)
    List<Examiner> getExaminerListByQuery(String query);
}
